package com.leijie.nio;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author LeiJie
 * @time 2020-5-11 11:04
 * @desc TODO
 */
public class NioTest9 {

    public static void main(String[] args) throws Exception{

        //随机读写 内存映射文件
        RandomAccessFile randomAccessFile = new RandomAccessFile("NioTest9.txt","rw");

        FileChannel channel = randomAccessFile.getChannel();

        MappedByteBuffer byteBuffer = channel.map(FileChannel.MapMode.READ_WRITE,0,5);
        byteBuffer.put(0,(byte) 'a');
        byteBuffer.put(3,(byte) 'b');

        randomAccessFile.close();
    }
}
